<!--
 * @Descripttion:
 * @Author: liuxiaoling
 * @Date: 2021-03-22 19:07:54
 * @LastEditors: liuxiaoling
 * @LastEditTime: 2021-03-28 18:40:26
-->
<template>
  <div class="page_browsingHistory">

    <com-top-nav-bar
      :topNavBarObj="topNavBarObj"
      @toGetKeywordOrDateStr="getKeyWordOrDateStr"
    />

    <div v-if="browsingHistoryList.length">
      <div
        v-for="(item, index) in browsingHistoryList"
        :key="index"
        style="position: relative;padding-top: 10px;background: #fff;"
      >
        <com-job-item :jobItem="item" :keyWord="'browsingHistory'"></com-job-item>
      </div>

      <van-pagination
        v-model="querySearchObj.pageIndex"
        :total-items="total"
        :items-per-page="querySearchObj.pageSize"
        @change="getPaginationValue_browse"
        force-ellipses
      >
        <template #prev-text>
          <van-icon name="arrow-left" />
        </template>
        <template #next-text>
          <van-icon name="arrow" />
        </template>
        <template #page="{ text }">{{ text }}</template>
      </van-pagination>
    </div>

    <van-divider style="margin-top: 80px" v-else>暂无记录</van-divider>
  </div>
</template>

<script>
import comJobItem from '../../components/comJobItem'
import comTopNavBar from "../../components/comTopNavBar";

export default {
  name: 'browsingHistory',
  components: {
    comJobItem,
    comTopNavBar,
  },
  data() {
    return {
      topNavBarObj: {
        title: '浏览记录',
        searchPlaceholder: '',
        dateLabel: '浏览记录',
        pathForLeft: '',
      },

      browsingHistoryList: [],
      total: 0,

      querySearchObj: {
        pageIndex: 1,
        pageSize: 10,
        keyword: '',
        browtime: '',
      },
    }
  },

  created() {
    // 浏览接口
    this._getBrowsingHistory(this.querySearchObj);
  },

  methods: {
    async _getBrowsingHistory(params) {
      const res = await this.$api.job.reqBrowsingHistory(params)
      if (res.code === 200) {
        this.browsingHistoryList = res.data.items
        this.total = res.data.count
      }
    },



    getPaginationValue_browse(val){
      console.log('翻页', val);
      // 指定页
      Object.assign(this.querySearchObj, {pageIndex: val})
      this._getBrowsingHistory(this.querySearchObj)
    },

    getKeyWordOrDateStr(val){
      const obj = {
        pageIndex: 1,
        keyword: val.keyword,
        browtime: val.date,
      }
      Object.assign(this.querySearchObj, obj)
      this._getBrowsingHistory(this.querySearchObj)
    },
  }
}
</script>

<style lang="scss" scoped></style>
